<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>async/await串行和并行</title>
</head>
<body>
<script>
    //串行
    {//先执行p1等P1执行完之后再执行p2
        let p1 = ()=>{//2
            return Promise.resolve("p1");
        }
        let p2 = ()=>{//3
            return Promise.resolve("p2");
        }
        let fn = async function(){ //a=>b=>c
            let p1Vale = await p1(); //2
            let p2Vale = await p2(); //3
            console.log(p1Vale,p2Vale); //5
        }
        fn();
    }
    //并行
    {//先执行p1等P1执行完之后再执行p2
        let p1 = ()=>{//2
            return Promise.resolve("p1");
        }
        let p2 = ()=>{//3
            return Promise.resolve("p2");
        }
        let fn = async function(){ //a //b //c
            let p1Data = p1();//2
            let p2Data = p2();//3
            let p1Vale = await p1Data; //2
            let p2Vale = await p2Data; //2+1
            console.log(p1Vale,p2Vale); //3
        }
        fn();
    }
    {//Promise.all
        let p1 = ()=>{//2
            return Promise.resolve("p1");
        }
        let p2 = ()=>{//3
            return Promise.resolve("p2");
        }
        let fn = async function(){ //a //b
            let pAll = await Promise.all([p1(),p2()]);//3
            console.log(pAll); //3
        }
        fn();
    }
</script>
</body>
</html>